package com.lei.datastructure.stack;

import java.util.Random;

/**
 * @Author LeiXiaoLei
 * @Date 2022/7/18 20:10
 * @Version 1.0
 */
public class Main {

    private static double testStack(Stack<Integer> stack, int opCount) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            stack.pop();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

    public static void main(String[] args) {
        Stack<Integer> linkedListStack = new LinkedListStack<>();
        Stack<Integer> arrayStack = new ArrayStack<>();
        int opCount = 100000000;
        System.out.println("LinkedListStack: " + testStack(linkedListStack,opCount) + "s");
        System.out.println("ArrayStack: " + testStack(arrayStack,opCount) + "s");
    }
}


